package com.lggry.interface3;

public class ClassDataInterImpl2 implements ClassDataInter{
    private Student[] students; //全部学生信息

    public ClassDataInterImpl2(Student[] students) {
        this.students = students;
    }
    @Override
    public void printAllStudentInfo() {
        int man = 0;
        int woman = 0;
        for (int i = 0; i < students.length; i++){
            Student s = students[i];
            if (s.getGender() == '男'){
                man++;
            }else {
                woman++;
            }
        }
        System.out.println("男学生人数为：" + man + "，女学生人数为：" + woman);
    }

    @Override
    public void printAverageScore() {
        double max = students[0].getScore();
        double min = students[0].getScore();
        double sum = 0;
        double aver = 0;
        for (int i = 0; i < students.length; i++){
            Student s = students[i];
            if (s.getScore() > max){
                max = s.getScore();
            }
            if (s.getScore() < min){
                min = s.getScore();
            }
        }
        for (int i = 0; i < students.length; i++){
            Student s = students[i];
            sum += s.getScore();
        }
        aver = (sum - max - min) / (students.length - 2);
        System.out.println("，平均分：" + aver);
    }
}
